import request from '@/utils/request'

interface ApiResponse<T = any> {
  code: number;
  msg: string;
  data: T;
}

interface PageResult<T> {
  records: T[];
  total: number;
  size: number;
  current: number;
  pages: number;
}

interface RoleItem {
  id?: number;
  name: string;
  code: string;
  status?: number;
  orderNum?: number;
  dataScope?: number;
  remark?: string;
}

export function getRoleList(params?: any): Promise<ApiResponse<RoleItem[]>> {
  return request({
    url: '/api/role/list',
    method: 'get',
    params
  })
}

export function getRolePage(params?: any): Promise<ApiResponse<PageResult<RoleItem>>> {
  return request({
    url: '/api/role/page',
    method: 'get',
    params
  })
}

export function addRole(data: any): Promise<ApiResponse<any>> {
  return request({
    url: '/api/role',
    method: 'post',
    data
  })
}

export function updateRole(data: any): Promise<ApiResponse<any>> {
  return request({
    url: '/api/role',
    method: 'put',
    data
  })
}

export function deleteRole(id: number): Promise<ApiResponse<any>> {
  return request({
    url: `/api/role/${id}`,
    method: 'delete'
  })
}

export function getRoleMenuIds(id: number): Promise<ApiResponse<number[]>> {
  return request({
    url: `/api/role/${id}/menuIds`,
    method: 'get'
  })
}

export function updateRoleMenus(id: number, data: any): Promise<ApiResponse<any>> {
  return request({
    url: `/api/role/${id}/menus`,
    method: 'put',
    data
  })
} 